package com.ceuer.demo.juc.function;

import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.function.Supplier;

/*
lambda表达式、函数式接口、Stream流式计算、链式编程
函数式接口测试
 */
public class FunctionTest {
	public static void main(String[] args) {
		//functionTest();
		//predicateTest();
		//consumerTest();
		supplierTest();
	}
	
	/**
	 * function函数式接口测试
	 */
	public static void functionTest() {
		// Function<String,String> function=new Function<String,String>() {
		// 	@Override
		// 	public String apply(String str) {
		// 		return "Hello，"+str;
		// 	}
		// };
		Function<String,String> function=(str)->{return "Hello，"+str;};
		System.out.println(function.apply("world！"));
	}
	
	/**
	 * Predicate断定型接口测试
	 */
	public static void predicateTest() {
		/*Predicate<String> predicate=new Predicate<String>() {
			@Override
			public boolean test(String str) {
				return str.isEmpty();
			}
		};*/
		Predicate<String> predicate=(str)->{return str.trim().isEmpty();};
		System.out.println(predicate.test("   "));
	}
	
	/**
	 * Consumer消费型接口测试
	 */
	public static void consumerTest() {
		/*Consumer<String> consumer=new Consumer<String>() {
			@Override
			public void accept(String str) {
				System.out.println(str);
			}
		};*/
		Consumer<String> consumer=(str)->{System.out.println(str);};
		consumer.accept("zhangsan");
	}
	
	/**
	 * Supplier供给型接口测试
	 */
	public static void supplierTest() {
		/*Supplier supplier=new Supplier() {
			@Override
			public Integer get() {
				return 1024;
			}
		};*/
		
		Supplier supplier=()->{return 1024;};
		System.out.println(supplier.get());
	}
}
